package com.hspedu.newData.dmsxl.双指针;

import org.junit.Test;

/**
 * @Author: yh
 * @description: 
 * @CreateTime: 2025-05-17 
 * @Version: 1.0
 */

public class LC75颜色分类 {

    public void sortColors(int[] nums) {
        int p0 = 0;
        int p1 = 0;

        for (int i = 0; i < nums.length; i++) {
            if (nums[i] == 0){
                int temp = nums[i];
                nums[i] = nums[p0];
                nums[p0] = temp;
                if (p0 < p1){
                    temp = nums[i];
                    nums[i] = nums[p1];
                    nums[p1] = temp;
                }
                p0++;
                p1++;
            }else if (nums[i] == 1){
                int temp = nums[i];
                nums[i] = nums[p1];
                nums[p1] = temp;
                p1++;
            }
        }
    }

    @Test
    public void test() {
        // 测试代码

        sortColors(new int[]{2,0,2,1,1,0});
    }
}
